/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.springapp.service.impl;

import com.springapp.model.Item;
import com.springapp.repository.ItemRepository;
import com.springapp.service.ItemService;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 *
 * @author vkrivtc
 */
@Service
@Transactional
public class ItemServiceImpl implements ItemService {

    @Autowired
    private ItemRepository itemRepository;

    public ItemServiceImpl() {}

    public Item getById(Integer id) {
        return itemRepository.findOne(id);
    }

    public List<Item> getAll() {
        return (ArrayList<Item>) itemRepository.findAll();
    }

    public void create(Item item) {
        itemRepository.save(item);
    }

    public Item update(Item item) {
        return itemRepository.save(item);
    }

    public void delete(Integer id) {
        itemRepository.delete(id);
    }
}